package com.xdf.data_transmitter.controller;

import com.xdf.data_transmitter.model.Area;
import com.xdf.data_transmitter.service.AreaService;
import com.xdf.data_transmitter.utils.BusinessException;
import com.xdf.data_transmitter.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/area")
@Slf4j
public class AreaController {

    @Autowired
    private AreaService service;

    @GetMapping("/selectAll")
    public JsonResult selectAll(){
        log.info("会先执行抛出异常！");
        if( 1==2 ){
            throw new BusinessException("area直接抛出异常！");
        }
        log.info("异常执行完毕！");
        System.out.println("抛出异常了，你不应该能看到我！");
        return JsonResult.ok(service.selectAll());
    }
}
